package Synchronized;



class WaitTask implements Runnable{
    private Object locker  = new Object();

    public WaitTask(Object locker) {
        this.locker = locker;
    }

    @Override
    public void run() {
        synchronized (locker)
        {
            try {
                System.out.println("开始阻塞...");
                locker.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }
    }
}
class NotifyTask implements Runnable{
    private Object locker = new Object();
    public NotifyTask(Object locker)
    {
       this.locker = locker;
    }
    @Override
    public void run() {
        synchronized (locker)
        {
               locker.notify();
            System.out.println("线程已经被唤醒...");
        }
    }
}
public class demo1 {
    public static void main(String[] args) throws InterruptedException {
        Object locker  =  new Object();
        Thread t1 = new Thread(new WaitTask(locker));
/*        Thread t2 = new Thread(new WaitTask(locker));
        Thread t3 = new Thread(new WaitTask(locker));*/
        Thread t4 = new Thread(new NotifyTask(locker));

        t1.start();
//        t2.start();
//        t3.start();
        Thread.sleep(5000);
        t4.start();
    }
}
